<template>
  <div class="details">
    <div class="appPc" v-if="$store.state.screenWidth > 1300">
      <div class="backdrop">
        <img
          src="https://ir3.anbio.xyz/uploads/image/6528681748657426.jpg"
          alt=""
        />
        <h1 class="title">Press Releases</h1>
      </div>

      <div class="block interval" v-loading="detailShow">
        <h2 class="title">{{ detailsObj.newTitle }}</h2>
        <div style="display: flex; align-items: center">
          <div class="time">{{ detailsObj.createTime }}</div>
          <div class="pdf" @click.stop="generatePDF(detailsObj)">
            <img src="../../assets/common/pdf-file_2.svg" alt="" />
          </div>
        </div>

        <div class="text">
          <p v-html="detailsObj.newContent"></p>
        </div>
      </div>
    </div>
    <div class="appH5" v-else>
      <div class="popup-lint"></div>

      <div class="backdrop">
        <img
          src="https://ir3.anbio.xyz/uploads/image/6528681748657426.jpg"
          alt=""
        />
        <h1 class="title">Press Releases</h1>
      </div>

      <div class="block" v-loading="detailShow">
        <h2 class="title">{{ detailsObj.newTitle }}</h2>
        <div style="display: flex; align-items: center">
          <div class="time">{{ detailsObj.createTime }}</div>
          <div class="pdf" @click.stop="generatePDF(detailsObj)">
            <img src="../../assets/common/pdf-file_2.svg" alt="" />
          </div>
        </div>
        <div class="text">
          <p v-html="detailsObj.newContent"></p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { newDetailGet } from "../../api/index";

import html2pdf from "html2pdf.js";

export default {
  name: "releasesId",
  data() {
    return {
      id: "",
      detailsObj: {},
      detailShow: true,
    };
  },
  created() {
    this.id = this.$route.params.id;

    this.newDetailMet();
    this.scrollTotap();
  },
  methods: {
    scrollTotap() {
      window.scrollTo(0, 0);
    },
    newDetailMet() {
      newDetailGet(this.id).then((res) => {
        if (res.errorCode == null) {
          this.detailsObj = res.resultData;
          this.detailShow = false;
        }
      });
    },

    //------------
    generatePDF(item) {
      const element = document.createElement("div");
      element.innerHTML = item.newContent;
      html2pdf(element, {
        margin: 0.5,
        filename: "report.pdf",
        image: { type: "jpeg", quality: 0.98 },
        html2canvas: { scale: 2 },
        jsPDF: { unit: "in", format: "letter", orientation: "portrait" },
      });
    },
  },
};
</script>

<style lang="less" scoped>
.details {
  .appPc {
    .backdrop {
      height: 205px;
      width: 100%;
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;

      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        position: absolute;
      }

      .title {
        letter-spacing: 1.5px;
        color: #fff;
        position: relative;
        font-size: 48px;
        font-weight: bold;
      }
    }
    .block {
      padding: 50px 20px;
      box-sizing: border-box;

      .title {
        font-size: 54px;
        font-weight: 500;
      }

      .time {
        font-size: 20px;
        font-weight: 500;
        margin-right: 20px;
        color: #838892;
      }

      .pdf {
        width: 30px;
        height: 30px;
        margin-right: 20px;
        cursor: pointer;

        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }

  .appH5 {
    .backdrop {
      height: 200px;
      width: 100%;
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;

      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        position: absolute;
      }

      .title {
        letter-spacing: 1.5px;
        color: #fff;
        position: relative;
        font-size: 24px;
        font-weight: bold;
      }
    }

    .block {
      margin: 0 10px;
      padding-bottom: 30px;

      .title {
        font-size: 24px;
      }

      .time {
        font-size: 18px;
      }

      .pdf {
        width: 20px;
        height: 20px;
        margin-left: 10px;

        img {
          width: 100%;
          height: 100%;
        }
      }

      .text {
        font-size: 2.1rem;
        /deep/ table {
          width: 100%;
        }

        /deep/ td,
        th {
          overflow: auto;
          word-wrap: break-word;
        }
      }
    }
  }
}
</style>
